<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="关键字" prop="name" label-width="68px">
        <el-input v-model="queryParams.name" placeholder="商品名称、场馆名称、商品编号" clearable style="width: 240px" @keyup.enter.native="handleQuery" />
      </el-form-item>

      <el-form-item label="是否启用" prop="isPutaway">
        <el-select v-model="queryParams.isPutaway" clearable style="width: 240px">
          <el-option v-for="dict in this.status" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="createDateRange" style="width: 340px" type="datetimerange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']" value-format="yyyy-MM-dd HH:mm:ss">
          ></el-date-picker>
      </el-form-item> -->
    <!-- <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item> -->
    <!-- </el-form> -->

    <el-table :height="tableHeight" ref="elTable" v-loading="loading" :data="list" stripe border>
      <el-table-column label="序号" type="index" width="60" align="center" />
      <el-table-column label="名称" prop="name" width="200" :sortable="'custom'" />
      <el-table-column label="商品编号" prop="goodsNo" align="center" width="120" :sortable="'custom'" />
      <el-table-column label="商品价(元)" :sortable="'custom'" prop="price" width="120" align="center" />
      <el-table-column label="零售价(元)" :sortable="'custom'" prop="retailPrice" width="120" align="center" />
      <el-table-column label="成本价(元)" :sortable="'custom'" prop="costPrice" width="120" align="center" v-if="checkPermi(['showroom:art:lookprice'])" />
      <el-table-column label="库存" :sortable="'custom'" prop="stock" width="120" align="center" />
      <el-table-column label="缩略图" prop="imgMin" align="center" width="150">
        <template slot-scope="scope">
          <table-image :imgDicUrls="scope.row.imgMin"></table-image>
        </template>
      </el-table-column>
      <el-table-column label="排序" sortable prop="orderNum" width="80" align="center" />
      <el-table-column label="创建时间" sortable prop="createTime" align="center" min-width="160" />
      <el-table-column label="操作" fixed="right" align="center" width="80">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="" @click.stop="selectGoods(scope.row)">选择</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listGoodsGiftSend } from "@/api/showroom/goods";
import tableImage from "@/components/TableImageView/index.vue";
import { excelExportApi } from '@/api/filer'
import formView from "./formView.vue";
import { checkPermi } from "@/utils/permission"; // 权限判断函数

export default {
  name: "goodsGiftSend", //赠品选择列表
  components: { tableImage, formView },

  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      list: [], //商品列表
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: this.global.pageSize,
        status: 1
      },
      pageNum: 1,
      // 表单参数
      form: {},

      status: [
        { label: "全部", value: null },
        { label: "启用", value: 1 },
        { label: "不启用", value: 0 },
      ]
    };

  },
  watch: {
    "queryParams": {
      deep: true,
      handler: function (newV, oldV) {
        console.log(newV.pageSize, this.queryParams.pageSize)
        if (this.pageNum == newV.pageNum) {
          this.handleQuery();
        } else {
          this.pageNum = newV.pageNum;
        }
      },
    },
    createDateRange(newV, oldV) {
      if (newV) {
        if (newV.length >= 2) {
          this.queryParams.createTimeStart = String(newV[0]);
          this.queryParams.createTimeEnd = String(newV[1]);
        }
      } else {
        this.queryParams.createTimeStart = undefined;
        this.queryParams.createTimeEnd = undefined;
      }
      this.getList();
    },
  },
  computed: {
    tableHeight() {
      return '400px'
    },
  },
  created() {
    this.getList();
  },
  methods: {
    checkPermi,
    getList() {
      this.loading = true;
      listGoodsGiftSend(this.queryParams)
        .then((response) => {
          if (response.code == 200) {
            this.list = response.data;
            this.total = response.total;
          }
          this.loading = false;
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    selectGoods(row) {
      this.$emit('selectGoods', row)
    }

  },
};
</script>
<style scoped>
</style>
